Repository navigation
fix(ssh-transport): fail fast on refused shell and exec requests - #1675
Merged
smart-ssh-coordinator[bot] merged 7 commits intoDec 5, 2026
Merged
smart-ssh-coordinator[bot] merged 7 commits into
smart-ssh-coordinator[bot] merged 7 commits into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
8 tasks
8 tasks
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
Blocking
crates/ssh-transport/src/transport.rs:316-330(open_shell,RequestReply::Refusedarm) — the shell half of acceptance criterion 4 has no test. The AC asks for "a refused shell request yieldsSSH_SHELL_UNAVAILABLE(unit test with a channel that answersFailure)". The tests that exist cover other things.request_reply_tests::test_failure_reply_is_refusedonly checks that the helper returnsRefused.test_refused_requests_map_to_the_new_codesbuildsSshError::ShellUnavailable("x")by hand and checks its code, so it would stay green whatever erroropen_shellreturns.error.rs:test_ssh_error_codes_are_uniqueonly checks the code table. Concrete scenario: if theRefusedarm inopen_shellreturnedChannelError, or fell through toOk(RusshShell)as before this PR, no test would fail.TestHandler::shell_request(tests/fixtures/test_server.rs:788) always answerschannel_success, so nothing in the suite sends a refused shell. Fix: give the in-process test server a way to refuse the shell request (e.g. a dedicated user name or a flag on the server, likerefused-execfor exec). Then add a test that callsopen_shellwithin a timeout and assertserr.code() == "SSH_SHELL_UNAVAILABLE". The exec half already has such a test:sudo_password.rs:test_refused_exec_request_is_exec_unavailable, which I confirmed red without the fix (see below).
Non-blocking
- AC 1 says "returns within 5 s with empty stdout". The PR documents a deviation: OpenSSH with
ForceCommand internal-sftprejects every non-SFTP session with its own notice ("This service allows sftp connections only.") and exit 1. That behaviour is on the server side, and no client can suppress it without hiding server output. The intent of the AC holds: there is no hang,unamenever runs, and the test rejects any other stdout. I am raising it here only so the deviation is visible to the maintainer; the coder has nothing to fix. - (uncertain)
transport.rs:150-158wait_for_request_replydrops every message that arrives beforeSuccess/Failure(Some(_) => continue). For exec, a server that sentData/ExitStatusbefore its reply would lose that output or the exit code. OpenSSH sends the reply before it starts the child, and the CI end-to-end job is green against OpenSSH and Dropbear, so this is theoretical. The reply wait also has no time limit; that matchesopen_sftpand the PR states it as an assumption. Listed under Follow-ups. - The
request_reply_testsand theauto_reconnectaddition would also pass ondevelop. That is expected for the auto-reconnect list, which is an allow-list (the AC only asks that the codes are not retried, and the test pins that). The helper tests are fine as tests of the helper; they do not replace the shell test above.
Verified
- files read: 6/6 logic and test files (
transport.rs,error.rs,auto_reconnect.rs,test_server.rs,sshd_sftp_only.rs,sudo_password.rs), plus scenario files, spec, changelog,errorCodes.tsand the en/de locales (read: full diff) - counter-proof:
sudo_password.rs:test_refused_exec_request_is_exec_unavailableis red withtransport.rsfromorigin/develop("a refused exec must not hang: Elapsed") and green with the PR (executed:git checkout origin/develop -- crates/ssh-transport/src/transport.rs && cargo test -p ssh-transport --test sudo_password test_refused_exec, then restored; working tree clean). Shell refusal: no test exists to run (blocking above). The io-sftponly tests could not be run here (they need the sshd containers). For those, I traced by reading the code that on the old code OpenSSH's forcedinternal-sftpcloses the channel after its notice, so AC 1–3 pass there too. The hang fix is proven byexec_without_stdin_of_cat_exits_zero(AC 5): without EOF,catwaits forever. That test is green in the CI "SSH end-to-end (Docker)" job. - edge cases: refused exec →
SSH_EXEC_UNAVAILABLEwithout waiting (executed test). Close/EOF/end of stream before the reply →SessionClosed(read +test_close_eof_or_end_before_reply_is_closed). Exec with empty stdin → EOF still sent, as before (read). sudo password prompt and SFTP over exec keep stdin open viaopen_exec_interactive(read;sudo_password.rs5 passed, executed). Long-runningstart_exec/execute_streamingwithout stdin now get EOF, which is harmless for non-interactive commands (read). - callers checked:
open_exec(6 call sites intransport.rs, all non-interactive) → ok;open_exec_sftp/sudo prompt → switched toopen_exec_interactive→ ok;SshErrorexhaustive matches (Display,code,ALL_CODES) → ok; frontendKNOWN_ERROR_CODESand all 25 locales → ok. - tests run locally:
cargo test -q -p ssh-transport→ 114 lib + 12 + 13 + 5 + 53 integration passed, sshd tests ignored as designed (executed);cargo test -p ssh-manager-core code_tests→ 5 passed (executed);cargo test -p app-logic --lib test_only_network_codes_are_retryable→ 1 passed (executed);npx vitest run src/api src/locales→ 300 passed (executed). - CI: all checks green, including "SSH end-to-end (Docker)" (read:
gh pr checks). - UI: not a UI change (only error texts for new codes).
- data: not touched.
Timing analysis
- 6 test files analysed.
sshd_sftp_only.rs:12(WITHIN= 5 s on a real container) and:33(shell read loop within 5 s) — tight real-clock bound, possible → non-blocking. The 5 s comes from the acceptance criteria themselves, and the clock starts after connect.sudo_password.rs:~1995 s hang guard against the in-process server → dismissed, a generous ceiling. Everything else is deterministic.
Spec
- visible behaviour changed: refused shell/exec now fail at once with the new error texts; an exec without stdin gets EOF; closing before the shell reply reports "session lost".
- spec searched (executed:
rg -il 'SSH_CHANNEL_ERROR|Kanalfehler|Channel-Fehler' docs/specs/→ 0005, 0069, 0085, 0086), spec covering it: 0005 §4.1, §4.4 and the error table. - verdict: spec change present and matches the code (0005 §4.1/§4.4 plus two table rows). Spec 0069 A3 does not list these codes and needs no change.
Security checks
- Elevated because of
crates/ssh-transport/andcrates/core/src/ssh/error.rs. Filter engine, approval andApprovedCommandare untouched; the change only waits for replies to requests already sent. Loosening: none. A refusal used to hang and now fails; the newClosedarm returns an error, so nothing fails open into a working channel. Bypass attempts considered: a server sendingSuccessafter unrelated messages → accepted, correct;Failure→ closed with an error;EofthenSuccess→ treated as closed, so no half-open shell; a stream that ends → error, notOk; a never-answering server → waits, same asopen_sftp(non-blocking). No new secrets, no new logging of content.Threat model: no changewith a sound reason, and the CI check is green.
Previous findings (follow-up round only)
- n/a (first review)
Follow-ups
- Request-reply wait discards channel data/exit status that arrive before the reply and has no time limit (applies to
open_sftpas well). No existing issue found.
…LE (#1665) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Review point 1 (shell refusal test): fixed in dadd3b2. The in-process test server now refuses the shell request on demand, and |
There was a problem hiding this comment.
Review
Verdict: approved
Review level: elevated
Blocking
None.
Non-blocking
crates/ssh-transport/tests/fixtures/test_server.rs:265-269— the newpub const REFUSE_SHELL_COLSsits between the existing doc comment ofRunningTestServerand the struct. Rustdoc now attaches the "Läuft einRunningTestServer…" comment to the constant, and the struct loses its doc. Style only (test fixture). Move the constant above the comment.- Still open from the first round (not part of this delta): the deviation from AC 1's "empty stdout" (OpenSSH's forced
internal-sftpprints its own notice). I raised it there for the maintainer; nothing for the coder to fix.
Verified
- files read: 2/2 changed test files in the delta
d22042e1..dadd3b22(tests/fixtures/test_server.rs,tests/sudo_password.rs), plus theopen_shellreply handling intransport.rs(read). The delta changes no production code. - counter-proof:
sudo_password.rs:test_refused_shell_request_is_shell_unavailablefails whentransport.rsandcrates/core/src/ssh/are taken fromorigin/develop("refused shell must fail":open_shellreturnsOkthere) and passes with the PR (executed:git checkout origin/develop -- crates/ssh-transport/src/transport.rs crates/core/src/ssh/ && cargo test -q -p ssh-transport --test sudo_password test_refused_shell, then restored; working tree clean). The assertion checkserr.code() == "SSH_SHELL_UNAVAILABLE", so aRefusedarm that mapped to any other error would also fail it. - edge cases: the refusal is triggered by a PTY width (13) that no other test uses (executed:
rgover thePtySizeuses in the tests) → ok. The set is per connection and per channel, so other tests and channels are not affected → ok (read). The server marks the channel before it answers the PTY request, andopen_shellsends the shell request only after that answer, so the test is ordered by the protocol (read). - callers checked:
TestHandler::pty_request/shell_requestare used by every in-process test. Shell behaviour only changes for width 13 → ok (executed: the fullssh-transportsuite is green). - tests run locally:
cargo test -q -p ssh-transport→ 114 lib + 53 + 12 + 13 + 6 (sudo_password) passed; sshd tests are ignored by design (executed). - CI: all checks green at
dadd3b22, including "SSH end-to-end (Docker)" andthreat-model-note(read:gh pr checks). The PR is mergeable. - UI: not a UI change.
- data: not touched.
Timing analysis
- 2 test files analysed (delta only): no timing dependency found. The 5 s
timeoutin the new test only guards against a hang; the expected path is one loopback round trip.
Spec
- visible behaviour changed: none in this delta (test-only). The spec verdict from the first round stands: spec 0005 §4.1, §4.4 and the error table are updated and match the code (search executed then:
rg -il 'SSH_CHANNEL_ERROR|Kanalfehler|Channel-Fehler' docs/specs/). - verdict: not needed for this delta, because it only adds a test and a fixture switch.
Security checks
- Elevated (
crates/ssh-transport/). The delta touches only test code, so there is no loosening and no change to the execution path. The checks from the first round stand: no fail-open (a refusal or close is an error, never a working channel); the filter engine, approval andApprovedCommandare untouched; the threat-model note is present and its CI check is green.
Previous findings (follow-up round only)
- Shell half of AC 4 had no test → fixed in dadd3b2 (
test_refused_shell_request_is_shell_unavailable, red without the fix, green with it).
Follow-ups
- The request-reply wait discards channel data or exit status that arrive before the reply, and it has no time limit (this applies to
open_sftpas well). No existing issue was found. Carried over from the first round; the issue is already labelledfollow-up-pending.
smart-ssh-coordinator
Bot
deleted the
issue-1665-ssh-transport-refused-or-forced-shell
branch
December 5, 2026 12:36
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1665
Summary
open_shelland exec now wait for the server's reply to the request (shared helperwait_for_request_reply).Failuregives the newSshError::ShellUnavailable(SSH_SHELL_UNAVAILABLE) /ExecUnavailable(SSH_EXEC_UNAVAILABLE);Close/Eofbefore the reply givesSessionClosed.open_exec_interactive).io-sftponlyandtests/sshd_sftp_only.rs.Acceptance Criteria
sshd_sftp_only.rs:execute_against_forced_sftp_returns_without_hanging_and_without_running_the_command(green in the SSH end-to-end CI job)open_shell_against_forced_sftp_fails_or_reports_session_closed(green in the SSH end-to-end CI job)open_sftp_against_forced_sftp_lists_the_chroot_root(green in the SSH end-to-end CI job)transport.rs:request_reply_tests::test_failure_reply_is_refused,test_refused_requests_map_to_the_new_codes,error.rs:test_ssh_error_codes_are_uniquecatreturns exit 0:sshd_sftp_only.rs:exec_without_stdin_of_cat_exits_zero(green in the SSH end-to-end CI job)auto_reconnect.rs:test_only_network_codes_are_retryableTests
Unit tests pass locally (ssh-transport lib, core error, app-logic auto_reconnect, locale parity). No counter-proof run for the unit tests beyond the scripted-reply design; real-server tests ran in CI. The in-process test server now accepts exec requests (as real servers do) and has a
refused-execcase:sudo_password.rs:test_refused_exec_request_is_exec_unavailable.Assumptions
open_sftp.Spec
updated 0005
Threat model: no change – transport only waits for replies to requests it already sent; no new connection, command path or secret.
Manual test steps
crates/ssh-transport/tests/sshd/run.shwith the new scenario.Follow-ups
None.
🤖 Generated with Claude Code